package org.mathig.poker.action;

import org.mathig.poker.PlayerListener;
import org.mathig.poker.PlayerWrapper;
import org.mathig.poker.table.TableHand;

public class CallAction extends PlayerAction {

	public CallAction(PlayerWrapper player, TableHand tableHand) {
		super(player, tableHand);
	}

	public void execute() {
		int toAdd = tableHand.getBet() - tableHand.getBet(player);

		toAdd = BetHelper.checkBet(tableHand, player, toAdd);
		BetHelper.addToBet(tableHand, player, toAdd);

		logger.info("{} call {}", player, tableHand.getBet(player));

		// fire event
		for (PlayerListener listener : tableHand.getPlayerListeners()) {
			if (listener != player)
				listener.playerCalled(player.getPlayer(), tableHand);
		}
	}

}
